﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace PlanesManagerWebAPI.Controllers
{
    public class AirportController : ApiController
    {
        public IHttpActionResult GetAll()
        {
            try
            {
                string token = Request.Headers.GetValues("token").FirstOrDefault();

                if (BusinessLoginLayer.Company_Details.ValidadeToken(token))
                {
                    CommonClasses.Airport[] airports = BusinessLoginLayer.Airports.GetAll();
                    return Ok(airports);
                }
                else
                {
                    System.Net.Http.Headers.AuthenticationHeaderValue v = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic");
                    return Unauthorized(v);
                }
            }
            catch (Exception)
            {
                return InternalServerError();
            }
        }

    }
}
